<template>
  <div class="hk-flex card-wk" style="flex-wrap: wrap;">
    <div
      v-for="(item, index) in (showAll?tabs:tabs.slice(0,11))"
      :key="index"
      class="card-container"
      :class="{ active: activeIndex == index }"
      @click="handleClick(index,item)"
    >
      <div class="card-pic">
        <img
          v-show="item.name=='全部规则'"
          style="width: 26px; height:26px"
          :src="require('@/assets/images/sjjr_jrsjy_all.png')"
          alt=""
        >
      </div>
      <div class="card-text hk-flex">
        <p class="card-title" style="max-width:134px;">{{ item.name }}</p>
        <span class="card-num" style="width:calc(100% - 134px)">{{ item.num>999?'999+':item.num }}</span>
        </p>
      </div>
    </div>
    <div v-if="!showAll && tabs.length>12" class="card-container" style="height:50px;" @click="showAll=!showAll">
      <div class="card-text hk-flex">
        <div class="card-pic" style="height:26px;" />
        <p class="card-title">更多...</p>
        <p class="card-sub-title">
          <!-- <span class="card-num">{{ item.num }}</span> -->
        </p>
      </div>
    </div>
    <span class="item-empty" />
    <span class="item-empty" />
    <span class="item-empty" />
    <span class="item-empty" />
    <span class="item-empty" />
  </div>
</template>

<script>
export default {
  name: 'TabList',
  props: {
    tabs: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      showAll: false,
      activeIndex: 0
    }
  },

  methods: {
    handleClick(index, val) {
      this.activeIndex = index
      this.showAll = false
      this.$emit('handleClick', index, val)
    }
  }
}
</script>

<style lang="scss" scoped>
.card-wk{
  margin-top:-10px;
  justify-content:space-around;
}
.card-container {
  width:16%;
  display: flex;
  height:50px;
  margin-top:10px;
  justify-content:flex-start;
  align-items: center;
  padding: 0 15px;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  // margin-bottom: 10px;
  cursor: pointer;
  justify-content: space-between;
  &:last-child{
    margin-right:0px;
  }
  .card-text{
    // justify-content: space-between;
    .card-title{
    flex:1;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  }

  .card-text{
    flex:1;
    margin-left:10px;
  }
}
.item-empty {
  height: 0px;
  width:16%;
}
.active {
  border-color: #2979ff;
  background: #e4eeff;
}
.card-num {
  color: #2979ff;
  width:calc(100% - 160px);
  text-align:right;
}
</style>
